package com.hepinghospital.user.ui.activity.eyecheck;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseActivity;
import com.hepinghospital.user.ui.activity.home.BookDoctor2Activity;
import com.hepinghospital.user.util.ImageLoaderHelper;
import com.hepinghospital.user.util.ToastUtil;
import com.rest.business.RestProxy;
import com.rest.observer.BaseObserver;
import com.rest.response.BaseJsonResponse;

import butterknife.BindView;
import butterknife.OnClick;
import jz.joyoung.robot.util.UtilString;

/**
 * 眼底，眼前节
 *
 * @time 2021/1/6 10:50
 */

public class EyeDiDetailActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.tv_eye_type)
    TextView tvEyeType;
    @BindView(R.id.tv_patient_name)
    TextView tvPatientName;
    @BindView(R.id.tv_eye_left)
    TextView tvEyeLeft;
    @BindView(R.id.tv_look_time)
    TextView tvLookTime;
    @BindView(R.id.tv_eye_hospital_name)
    TextView tvEyeHospitalName;
    @BindView(R.id.tv_eye_di_left)
    TextView tvEyeDiLeft;
    @BindView(R.id.iv_eye_left)
    ImageView ivEyeLeft;
    @BindView(R.id.tv_eye_di_right)
    TextView tvEyeDiRight;
    @BindView(R.id.iv_eye_right)
    ImageView ivEyeRight;
    @BindView(R.id.tv_save_eye)
    TextView tvSaveEye;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    String checkDetailId, oDUrl, url, osUrl;


    @Override
    protected void initViews() {
        tvTitle.setText("检查记录");
    }

    @Override
    protected void initData() {
        checkDetailId = getIntent().getStringExtra("checkDetailId");
        queryCheckDetail();
    }


    @Override
    protected int getLayoutResource() {
        return R.layout.activity_eye_di_detail;
    }


    private void queryCheckDetail() {
        RestProxy.getInstance().queryCheckDetail(checkDetailId, new BaseObserver<BaseJsonResponse>() {
            @Override
            public void onSuccess(BaseJsonResponse baseJsonResponse) {
                Log.e("checkDetailId333---", baseJsonResponse.checkItem);
                try {
                    tvEyeType.setText(baseJsonResponse.checkItem);
                    tvPatientName.setText(baseJsonResponse.patientName);
                    tvEyeHospitalName.setText(baseJsonResponse.hosName);
                    tvLookTime.setText(baseJsonResponse.checkTime);
                    tvEyeLeft.setText(baseJsonResponse.checkSeries);
                    osUrl = baseJsonResponse.oS;
                    oDUrl = baseJsonResponse.oD;
                    if (!UtilString.isEmpty(osUrl)) {
                        tvEyeDiLeft.setVisibility(View.VISIBLE);
                        ivEyeLeft.setVisibility(View.VISIBLE);
                        ImageLoaderHelper.getInstance().GlideImageLoader(mContext, osUrl, ivEyeLeft, R.mipmap.icon_eye_error);
                    } else {
                        tvEyeDiLeft.setVisibility(View.GONE);
                        ivEyeLeft.setVisibility(View.GONE);
                    }
                    if (!UtilString.isEmpty(oDUrl)) {
                        tvEyeDiRight.setVisibility(View.VISIBLE);
                        ivEyeRight.setVisibility(View.VISIBLE);
                        ImageLoaderHelper.getInstance().GlideImageLoader(mContext, oDUrl, ivEyeRight, R.mipmap.icon_eye_error);
                    } else {
                        tvEyeDiRight.setVisibility(View.GONE);
                        ivEyeRight.setVisibility(View.GONE);
                    }
                } catch (Exception e) {
                    // 捕获异常，如果要捕获Json数据异常，写catch(JSONException e)
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable e) {
                ToastUtil.onError(mContext, e);
            }
        });
    }


    @OnClick({R.id.iv_eye_left, R.id.iv_eye_right, R.id.tv_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_eye_left:
                Bundle bundle = new Bundle();
                bundle.putString("url", osUrl);
                bundle.putInt("type", 1);
                startActivity(BigImageActivity.class, bundle);
                break;
            case R.id.iv_eye_right:
                Bundle bundleRight = new Bundle();
                bundleRight.putString("url", oDUrl);
                bundleRight.putInt("type", 1);
                startActivity(BigImageActivity.class, bundleRight);
                break;
            case R.id.tv_submit:
                Bundle bundleOne = new Bundle();
                bundleOne.putInt("type", 1);
                bundleOne.putString("checkDetailId", checkDetailId);
                startActivity(BookDoctor2Activity.class, bundleOne);
                break;
            default:
                break;
        }
    }
}
